package thread.threaddemo;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @Author: wenjingyuan
 * @Date: 2023/02/01/14:05
 * @Description:wait带参数是否能被唤醒
 */
public class WaitDemo6 {
    public static void main(String[] args) {
        Object lock=new Object();

        new Thread(()->{
            System.out.println("线程1：开始执行");
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程1：执行结束");
            }

        },"无参wait线程").start();
        new Thread(()->{
            synchronized (lock){
                System.out.println("线程2：开始执行"+ LocalDateTime.now());
                try {
                    lock.wait(60*60*1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程2：结束执行"+LocalDateTime.now());
            }
        },"有参wait线程").start();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock){
                System.out.println("唤醒所有线程");
                lock.notifyAll();
            }
        }).start();
    }
}
